package it.polimi.traveldream.ejb.entities;

import it.polimi.traveldream.ejbclient.dtos.TransportDTO;

import java.io.Serializable;

import javax.persistence.*;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;


/**
 * The persistent class for the transport database table.
 * 
 */
@Entity
@NamedQueries({
	@NamedQuery(name=Transport.FIND_TRANSPORTS_AVAILABLE,
			query="SELECT t FROM Transport t WHERE t.startTrip >= :start AND t.endTrip <= :end AND t.maxAvailability - t.reservations >= :reservations"),
	@NamedQuery(name=Transport.FIND_TRANSPORTS,
			query="SELECT t FROM Transport t WHERE t.overpast = :overpast")
})
public class Transport implements Serializable {
	private static final long serialVersionUID = -2350985821201076651L;
	public static final String FIND_TRANSPORTS_AVAILABLE = "Transport.findTransportsAvailable";
	public static final String FIND_TRANSPORTS = "Transport.findTransports";
	private int id;
	private String arrivalCity;
	private String company;
	private String departureCity;
	private String description;
	private Date endTrip;
	private int maxAvailability;
	private boolean overpast;
	private BigDecimal price;
	private int reservations;
	private Date startTrip;
	private List<Travelpackage> travelpackages;

	public Transport() {
		super();
	}

	public Transport(TransportDTO transport) {
		super();
		this.id = transport.getId();
		this.arrivalCity = transport.getArrivalCity();
		this.company = transport.getCompany();
		this.departureCity = transport.getDepartureCity();
		this.description = transport.getDescription();
		this.endTrip = transport.getEndTrip();
		this.maxAvailability = transport.getMaxAvailability();
		this.overpast = transport.isOverpast();
		this.price = transport.getPrice();
		this.reservations = transport.getReservations();
		this.startTrip = transport.getStartTrip();
	}


	@Id
	@GeneratedValue(strategy=GenerationType.IDENTITY)
	public int getId() {
		return this.id;
	}

	public void setId(int id) {
		this.id = id;
	}


	public String getArrivalCity() {
		return this.arrivalCity;
	}

	public void setArrivalCity(String arrivalCity) {
		this.arrivalCity = arrivalCity;
	}


	public String getCompany() {
		return this.company;
	}

	public void setCompany(String company) {
		this.company = company;
	}


	public String getDepartureCity() {
		return this.departureCity;
	}

	public void setDepartureCity(String departureCity) {
		this.departureCity = departureCity;
	}


	public String getDescription() {
		return this.description;
	}

	public void setDescription(String description) {
		this.description = description;
	}


	@Temporal(TemporalType.TIMESTAMP)
	public Date getEndTrip() {
		return this.endTrip;
	}

	public void setEndTrip(Date endTrip) {
		this.endTrip = endTrip;
	}


	public int getMaxAvailability() {
		return this.maxAvailability;
	}

	public void setMaxAvailability(int maxAvailability) {
		this.maxAvailability = maxAvailability;
	}


	public boolean getOverpast() {
		return this.overpast;
	}

	public void setOverpast(boolean overpast) {
		this.overpast = overpast;
	}


	public BigDecimal getPrice() {
		return this.price;
	}

	public void setPrice(BigDecimal price) {
		this.price = price;
	}


	public int getReservations() {
		return this.reservations;
	}

	public void setReservations(int reservations) {
		this.reservations = reservations;
	}


	@Temporal(TemporalType.TIMESTAMP)
	public Date getStartTrip() {
		return this.startTrip;
	}

	public void setStartTrip(Date startTrip) {
		this.startTrip = startTrip;
	}


	//bi-directional many-to-many association to Travelpackage
	@ManyToMany(mappedBy="transports")
	public List<Travelpackage> getTravelpackages() {
		return this.travelpackages;
	}

	public void setTravelpackages(List<Travelpackage> travelpackages) {
		this.travelpackages = travelpackages;
	}

}